package edu.dayu.interceptor;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.util.Properties;

@Intercepts({
        @Signature(type = StatementHandler.class, method = "prepare",
                args = {Connection.class, Integer.class})
})
public class ExecutorInterceptor implements Interceptor {
     private  static Logger logger = LoggerFactory.getLogger(ExecutorInterceptor.class);

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        logger.info("执行方法前");
        StatementHandler target = (StatementHandler) invocation.getTarget();
        String sql = target.getBoundSql().getSql();
        logger.info("SQL："+sql);
        Object proceed = invocation.proceed();
        logger.info("执行方法后");
        return proceed;
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target,this);
    }

    @Override
    public void setProperties(Properties properties) {
        logger.info("-------------获取自定义配置参数-------------");
    }
}
